<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <link rel="stylesheet" href="<%=basePath%>/css/ztreecss/zTreeStyle/zTreeStyle.css" type="text/css">
    <link type="text/css" rel="stylesheet" href="<%=basePath%>/script/ligerUI/skins/Aqua/css/ligerui-all.css">
	<script type="text/javascript" src="<%=basePath%>/script/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>/script/ztreejs/jquery.ztree.core-3.3.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>/script/ztreejs/jquery.ztree.excheck-3.3.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>/script/ztreejs/jquery.ztree.exedit-3.3.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>/script/ligerUI/js/ligerui.min.js"></script>
  		<script type="text/javascript">
		<!--
		var tab = null;
		var setting = {
			async: {
				enable: true,
				url:"<%=basePath%>/cas/chaptertips_ajaxtree.action",
				dataFilter: filter
			},
			edit: {
				enable: true,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeClick: beforeClick,
				onClick: onClick
			}
		};

		var zNodes =[
			{ id:1, pId:0, name:"父节点1 - 展开", open:true},
			{ id:11, pId:1, name:"父节点11 - 折叠"},
			{ id:111, pId:11, name:"叶子节点111"},
			{ id:112, pId:11, name:"叶子节点112"},
			{ id:113, pId:11, name:"叶子节点113"},
			{ id:114, pId:11, name:"叶子节点114"},
			{ id:12, pId:1, name:"父节点12 - 折叠"},
			{ id:121, pId:12, name:"叶子节点121"},
			{ id:122, pId:12, name:"叶子节点122"},
			{ id:123, pId:12, name:"叶子节点123"},
			{ id:124, pId:12, name:"叶子节点124"},
			{ id:13, pId:1, name:"父节点13 - 没有子节点", isParent:true},
			{ id:2, pId:0, name:"父节点2 - 折叠"},
			{ id:21, pId:2, name:"父节点21 - 展开", open:true},
			{ id:211, pId:21, name:"叶子节点211"},
			{ id:212, pId:21, name:"叶子节点212"},
			{ id:213, pId:21, name:"叶子节点213"},
			{ id:214, pId:21, name:"叶子节点214"},
			{ id:22, pId:2, name:"父节点22 - 折叠"},
			{ id:221, pId:22, name:"叶子节点221"},
			{ id:222, pId:22, name:"叶子节点222"},
			{ id:223, pId:22, name:"叶子节点223"},
			{ id:224, pId:22, name:"叶子节点224"},
			{ id:23, pId:2, name:"父节点23 - 折叠"},
			{ id:231, pId:23, name:"叶子节点231"},
			{ id:232, pId:23, name:"叶子节点232"},
			{ id:233, pId:23, name:"叶子节点233"},
			{ id:234, pId:23, name:"叶子节点234"},
			{ id:3, pId:0, name:"父节点3 - 没有子节点", isParent:true}
		];
		function filter(treeId, parentNode, childNodes) {
			if (!childNodes) return null;
			var childNode=childNodes.message;
			var nodejson=eval('(' + childNode + ')');
			for (var i=0, l=nodejson.length; i<l; i++) {
				nodejson[i].name = nodejson[i].name.replace(/\.n/g, '.');
			}
			return  nodejson;
		}
		jQuery(document).ready(function(){
			jQuery.fn.zTree.init(jQuery("#treeDemo"), setting);
			//布局
			jQuery("#layout1").ligerLayout({ leftWidth: 360, height: '100%'});
			//tab
			var height = $(".l-layout-center").height();
			jQuery("#framecenter").ligerTab({ height: height });
			tab = $("#framecenter").ligerGetTabManager();
		});
		function beforeClick(treeId, treeNode, clickFlag) {
			
		}
		function onClick(event, treeId, treeNode, clickFlag) {
			addTab(treeNode.id,treeNode.name,"<%=basePath%>cas/chaptertips_show.action?id="+treeNode.id);
		}
		function addDate(){
			addTab("newdate","新建知识点","<%=basePath%>cas/chaptertips_add.action");
		}
		function addDateYe(){
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getSelectedNodes(),
			treeNode = nodes[0];
			if (nodes.length == 0) {
				alert("请先选择一个节点");
				return;
			}else{
				addTab("newdate","新建知识点","<%=basePath%>cas/chaptertips_add.action?treeNodeid="+treeNode.id);
			}
		}
		function addTab(id,name,url){
			var count=tab.getTabItemCount();
			var currentTabid =tab.getSelectedTabItemID();
			if(count>=2){
				if (currentTabid == "home") return;
				tab.overrideTabItem(currentTabid, { tabid:id,url:url,text:name});
			}else{
				tab.addTabItem({ tabid :id,text:name, url: url });
			}
		}
		function resettree(){
			asyncForAll = false;
			goAsync = false;
			$("#demoMsg").text("");
			$.fn.zTree.init($("#treeDemo"), setting);
		}
		//-->
	</script>
  </head>
  
  <body>
  <div id="pageloading"></div>  
	<div id="topmenu" class="l-topmenu">
	   <input type="button" value="新建父节点"  onclick="addDate();"/>
	   <input type="button" value="新建叶子节点"  onclick="addDateYe();"/>
	   <input type="button" value="更新节点"  onclick="resettree();"/>
	</div>
      <div id="layout1" style="width:99.2%; margin:0 auto; margin-top:4px;">
            <div position="left">
            	  <div class="content_wrap">
				    <div class="zTreeDemoBackground left">
						<ul id="treeDemo" class="ztree"></ul>
					</div>
				  </div>
            </div>
            	<!--  右边 -->
            	<div position="center" id="framecenter"> 
		            <div tabid="home" title="使用说明" style="height:300px" >
		                <!-- <iframe frameborder="0" name="home" src="./wecome.jsp"></iframe> -->
		            </div> 
        		</div> 
        		<!--  右边 -->
        </div> 

  </body>
</html>
